

uniform float speed;
uniform vec4 color;
uniform sampler2D iChannel0;
vec2 center = vec2(.5 ,.5);

#define time czm_frameNumber * speed /1000.
#define tau 6.2831853

mat2 makem2(in float theta){float c = cos(theta);float s = sin(theta);return mat2(c,-s,s,c);}
float noise( in vec2 x ){return texture2D(iChannel0, x*.01).x;}

float fbm(in vec2 p)
{	
  float z=2.;
  float rz = 0.;
  vec2 bp = p;
  for (float i= 1.;i < 6.;i++)
  {
    rz+= abs((noise(p)-0.5)*2.)/z;
    z = z*2.;
    p = p*2.;
  }
  return rz;
}

float dualfbm(in vec2 p)
{
    //get two rotated fbm calls and displace the domain
  vec2 p2 = p*.7;
  vec2 basis = vec2(fbm(p2-time*1.6),fbm(p2+time*1.7));
  basis = (basis-.5)*0.76;
  p += basis;
  
  //coloring
  return fbm(p*makem2(time*0.72));
}

float circ(vec2 p) 
{
  float r = length(p);
  r = log(sqrt(r));
  return abs(mod(r*5.1,tau)-3.14)*3.+.2;

}

czm_material czm_getMaterial(czm_materialInput materialInput){
  czm_material material = czm_getDefaultMaterial(materialInput);
  vec2 v_st = materialInput.st; // 获取uv坐标
  
  vec2 uv = v_st;
  vec2 p = vec2( center.x  -uv.x, center.y -uv.y);

  p*=4.;

  float rz = dualfbm(p);

  //rings
  p /= exp(mod(3.*10.,3.14159));
  rz *= pow(abs((0.1-circ(p))),.9);
  
  vec2 center2 = vec2(0.5, 0.5);
  
  float d = length(uv - center2);
  float r = 0.4;
  float a = 1.0;
  if(d > r) {
      a = max(0.0, 1.0 - ((d - r) / 0.1));
  }
    

  //final color
  vec3 col = color.rgb /rz;
  col=pow(abs(col),vec3( .99));
    col *= a;
    
  vec4 fragColor = vec4(col,1.);
  material.diffuse = fragColor.rgb * a;
  material.alpha = pow(a,2.0);
  return material;
}